/*******************************************************************************
 *
 *      Filename: Texture.h
 *   Description: Texture class for OpenGL textures
 *        Author: [kb]ypp
 *    Created at: May 27, 2005
 * Last modified: October 19, 2005
 *
 ******************************************************************************/

 
#ifndef TEXTURE_H
#define TEXTURE_H

#include <GL/gl.h>
//#include <stdexcept>
#include <string>

//! @brief Texture class
//!
//! ...
class Texture {
public:
	// Exception class:
	/*class TextureError : public std::runtime_error {
	public:
		TextureError( const char *msg )
			: std::runtime_error( msg ) {}
	};*/
	
	/*//! @brief Texture target flags
	enum /Target/ {
		TEXTURE_1D = GL_TEXTURE_1D, //!< 1D texture
		TEXTURE_2D = GL_TEXTURE_2D  //!< 2D texture
		/ reserved:
		TEXTURE_3D = GL_TEXTURE_3D,
		TEXTURE_CUBE = GL_TEXTURE_CUBE_MAP,
		TEXTURE_RECT = GL_TEXTURE_RECTANGLE_ARB,/
	};*/
	
	//! @brief Texture parameters
	enum /*Parameters*/ {
		// Texture wrap modes:
		CLAMP =           1 << 0, //!< Wrap: Clamp texture
		CLAMP_TO_EDGE =   1 << 1, //!< Wrap: Clamp to edge
		CLAMP_TO_BORDER = 1 << 2, //!< Wrap: Clamp to border
		REPEAT =          1 << 3, //!< Wrap: Repeat texture
		MIRRORED_REPEAT = 1 << 4, //!< Wrap: Texture mirrored repeat
		// Texture filters:
		NEAREST =                1 << 5,  //!< Filter: Point sampling (no filter)
		LINEAR =                 1 << 6,  //!< Filter: Bilinear
		NEAREST_MIPMAP_NEAREST = 1 << 7,  //!< Filter: With mipmapping
		NEAREST_MIPMAP_LINEAR =  1 << 8,  //!< Filter: Bilinear with mipmapping
		LINEAR_MIPMAP_NEAREST =  1 << 9,  //!< Filter: Bilinear with mipmapping
		LINEAR_MIPMAP_LINEAR =   1 << 10  //!< Filter: Trilinear
		// Format:
		/*RGB =             1 << 11,
		RGBA =            1 << 12,
		LUMINANCE =       1 << 13,
		LUMINANCE_ALPHA = 1 << 14*/
		//DEPTH =           1 << 15
		// ...put other flags here
	};
	
	Texture( GLenum target = GL_TEXTURE_2D );
	Texture( const std::string &filename, GLenum target = GL_TEXTURE_2D,
		int params = REPEAT | LINEAR_MIPMAP_LINEAR );
	virtual ~Texture();
	
	void load( const std::string &fname,
		int params = REPEAT | LINEAR_MIPMAP_LINEAR );
	
	void bind() const;
	void bind( int unit ) const;
	void enable() const;
	void enable( int unit ) const;
	void disable() const;
	void disable( int unit ) const;
	
private:
	//! @brief Disable copy-construction
	Texture( const Texture& );
	//! @brief Disable assignment
	Texture& operator=( const Texture& );
	//! @brief Set texture parameters
	void setParameters( int flags );
	
	/*unsigned char* read( const std::string &fname );
	unsigned char* read_jpeg( const std::string &fname );
	unsigned char* read_png( const std::string &fname );*/
	
	GLuint id;
	GLenum target;
	/*GLenum internalFormat;
	GLenum format;
	GLenum type;*/
	
	//int flags;
	//GLenum format;
	//int width, height, depth;
};

#endif // TEXTURE_H
